/**
 * 
 */
package xxm.utility.pack;

import java.nio.ByteBuffer;
import java.util.Arrays;

/**
 * @author xxm
 *
 */
public class BasicByteBufferHelp {

	/**
	 * Sets this buffer's position value is zero.
	 * @param buffer
	 */
	public static void resetByteBuffer( ByteBuffer buffer ) {
		if( buffer != null ) {
			buffer.position(0);
			//buffer.clear();
		}
	}
	
	/**
	 * ZeroMemory buffer, but reset buffer's position
	 * @param buffer
	 */
	public static void zeroMemoryByteBuffer(ByteBuffer buffer) {
		if( buffer != null ) {
			Arrays.fill(buffer.array(), (byte)0x0);
		}
	}
	
	/**
	 * ZeroMemory buffer, and reset buffer's position
	 * @param buffer
	 */
	public static void clearByteBuffer(ByteBuffer buffer) {
		if( buffer != null ) {
			BasicByteBufferHelp.zeroMemoryByteBuffer(buffer);
			buffer.clear();
		}
	}
}
